
package entity;

import java.util.List;

/**
 * Values and methods for specifying the GEO property
 * for the iCalendar object as defined in RFFC 5545.
 * This property specifies information related to the
 * global position for the activity specified by a 
 * calendar component.
 * 
 * @author Sean Young
 * @version 1.0
 *
 */
public class GeographicPosition {
        
        /** A String containing the parameters for the GEO property*/
        private String geoparam;
        
        /** The latitude coordinates */
        private float latitude;
        
        /** The longitude coordinates */
        private float longitude;
        
        /**
         * The constructor for the GEO property. The coordinates 
         * are defaulted to 0.
         */
        public GeographicPosition() {
                this.latitude = 0;
                this.longitude = 0;
        }
        
        /**
         * The constructor for the GEO property. The coordinates 
         * are set to the values sent as parameters.
         * @param latitude The latitude coordinates
         * @param longitude The longitude coordinates
         */
        public GeographicPosition(float latitude, float longitude) {
                this.latitude = latitude;
                this.longitude = longitude;
        }
        
        /**
         * Sets the value of the parameter for the GEO property.
         *
         * @param geoparam The parameter to be added to the GEO Property.
         *                 The parameter must be a single parameter.
         */
        public void setGeoParam(String geoparam) {
                this.geoparam = geoparam;
        }
        
        
        /**
         * Sets the value of the parameter for the GEO property.
         * @param geoparams A list of parameters to be added to the GEO property.
         */
        public void setGeoParam(List<String> geoparams) {
                StringBuilder parameterBuilder = new StringBuilder(" ");
                for(int i = 0; i < geoparams.size(); i++) {
                        parameterBuilder.append(geoparams.get(i));
                        if((geoparams.size() != 1) && (i != geoparams.size() - 1)) parameterBuilder.append(";");
                }
                this.geoparam = parameterBuilder.toString();
        }
        
        /**
         * Sets the value of the GEO property.
         * @param latitude The latitude coordinates
         * @param longitude The longitude coordinates
         */
        public void setGeoPos(float latitude, float longitude) {
                this.latitude = latitude;
                this.longitude = longitude;
        }
        
        /**
         * Sets the latitude coordinates of the GEO property
         * @param latitude The latitude coordinates
         */
        public void setLatitude(float latitude) {
                this.latitude = latitude;
        }
        
        /**
         * Sets the longitude coordinates of the GEO property
         * @param longitude The longitude coordinates
         */
        public void setLongitude(float longitude) {
                this.longitude = longitude;
        }
        
        /**
         * Returns a string containing the values of the fields of the
         * GEO property. If no parameters were specified then they 
         * won't be included. 
         * @return A string
         */
        public String toString() {
                StringBuilder geoString = new StringBuilder("GEO");
                
                if(geoparam != null) {
                	geoString.append(";");
                	geoString.append(geoparam);
                }
                
                geoString.append(":");          
                
                geoString.append(latitude);
                geoString.append(";");
                geoString.append(longitude);
                geoString.append("\r\n");
                
                return geoString.toString();
        }
        
}
